package com.globalwave.common;

import java.util.ArrayList;

public class ArrayOrderList extends ArrayList<Object> {

    private static final long serialVersionUID = 1L;

    public static class Asc {
        public Asc(String name) {
            this.name = name ;
        }
        public String name ;
    }
    
    public static class Desc {
        public Desc(String name) {
            this.name = name ;
        }
        public String name ;
    }
    
    public void addAsc(String name) {
        this.add(new Asc(name)) ;
    }
    
    public void addDesc(String name) {
        this.add(new Desc(name)) ;
    }
    
    public String toOrderString() {
        String result = "" ;
        for (Object obj : this) {
            if (obj instanceof Asc) {
                result += ((Asc)obj).name + " asc ," ;
            } else if (obj instanceof Desc) {
                result += ((Desc)obj).name + " desc ," ;                
            }
        }
        
        if (!"".equals(result)) {
            result = " order by " + result.substring(0,result.length() - 1 ) ;
        }
        
        return result ;
    }
}
